<template>
  <div class="admin-home">
    <div style="width: 100%;display: flex;justify-content: center;">
      <div style="width: 30%">
        <div style="margin: 10px">
          <div ref="chartRef1" style="width:100%; height: 400px;"></div>
        </div>
      </div>
      <div style="width: 40%;height: auto;">
        <div class="carousel" style=" width: 100%;height: auto; ">
          <a-carousel arrows>
            <template #prevArrow>
              <div class="custom-slick-arrow" style="left: 10px; z-index: 1">
                <left-circle-outlined/>
              </div>
            </template>
            <template #nextArrow>
              <div class="custom-slick-arrow" style="right: 10px">
                <right-circle-outlined/>
              </div>
            </template>
            <div class="carousel-item"><img alt="" src="../../../assets/image/img1.png"
                                            style="width: 100%;height: 400px"></div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/2.jpg" style="width: 100%;height: 400px">
            </div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/3.jpg" style="width: 100%;height: 400px">
            </div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/4.jpg" style="width: 100%;height: 400px">
            </div>
          </a-carousel>
        </div>
      </div>
      <div style="width: 30%">
        <div style="margin: 10px">
          <div ref="chartRef2" style="width: 100%; height: 400px;"></div>
        </div>
      </div>
    </div>
    <!--    公告-->
    <div style="width: 100%;display: flex;justify-content: center;">
      <div>
        <a-modal v-model:open="open" :title=textTitle width="1000px">
          <span v-html="truncateText1(textContent)"></span>
          <template #footer>
            <a-button key="submit" type="primary" @click="handleOk">关闭</a-button>
          </template>
        </a-modal>
      </div>
      <div  style="width: 100%;height: auto; border-radius: 20px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);">
        <a-input-search
            v-model:value="data.searchName"
            allow-clear
            enter-button
            placeholder="输入公告标题"
            size="middle"
            style="width: 30%; padding: 10px;margin-left: 8px;"
            @search="onSearch"
        />
        <div class="div-2">
          <a-list :data-source="listData" :pagination="pagination"
                  size="small"
                  style="width: 100%;margin-bottom: 30px;padding-right: 20px"
          >
            <template #renderItem="{ item }">
              <a-list-item :key="item.bulletinTitle" class="list-item">
                <a-card :title="item.bulletinTitle" style="width: 100%">
                  <template #extra>
                    <a-button type="link" @click="showModal(item.bulletinId)">查看</a-button>
                  </template>
                  <span v-html="truncateText2(item.bulletinText)"></span>
                </a-card>
              </a-list-item>
            </template>
          </a-list>
        </div>

      </div>
    </div>
  </div>

</template>
<script setup>
import {LeftCircleOutlined, RightCircleOutlined} from '@ant-design/icons-vue';
import * as echarts from "echarts";

//折现图
const chartRef1 = ref(null);
const setChart1 = async (enterpriseUserId) => {
  const chartDom = chartRef1.value;
  const myChart = echarts.init(chartDom);

  // 折线图配置项
  const res = await queryInformationByUserIdAPI(enterpriseUserId);
  const enterpriseId= res.data.data.enterpriseId;
  const res1 = await querySendRecordChangeAPI(enterpriseId);
  const sendRecordChange = {
    one: res1.data.data.oneWeekCount,
    two: res1.data.data.twoWeekCount,
    three: res1.data.data.threeWeekCount,
    four: res1.data.data.fourWeekCount,
    five: res1.data.data.fiveWeekCount,
    six: res1.data.data.sixWeekCount,
    seven: res1.data.data.sevenWeekCount
  }

  const option = {
    title: {
      text: '近七周投递数量变化情况'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: '7%',
      left: 'center'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      feature: {
        saveAsImage: {}
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['六周前', '五周前', '四周前', '三周前', '两周前', '一周前', '本周']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: '投递',
        type: 'line',
        stack: 'Total',
        data: [sendRecordChange.seven, sendRecordChange.six, sendRecordChange.five, sendRecordChange.four, sendRecordChange.three, sendRecordChange.two, sendRecordChange.one],
        itemStyle: {
          color: 'red' // 将折线颜色设置为红色，这里使用颜色名称'red'，也可以使用十六进制颜色码如'#FF0000'等
        }
      },

    ]
  };
  // 使用配置项显示图表
  myChart.setOption(option);
}
//饼图
const chartRef2 = ref(null);
const setChart2 = async () => {
  //饼图
  const chartDom2 = chartRef2.value;
  const myChart2 = echarts.init(chartDom2);

  // 饼图配置项
  const res = await queryInformationByUserIdAPI(enterpriseUserId);
  const enterpriseId= res.data.data.enterpriseId;
  const res1 = await querySendRecordSpreadAPI(enterpriseId);
  const sendRecordSpread = {
    collegeCount: res1.data.data.collegeCount,
    bachelorCount: res1.data.data.bachelorCount,
    masterCount: res1.data.data.masterCount,
    doctorCount: res1.data.data.doctorCount,
    otherCount: res1.data.data.otherCount,
  }

  const option2 = {
    title: {
      text: '近七周投递学历占比情况',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '7%',
      left: 'center'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center', // 将文字位置设置在内部，还可以是其他值如 'outside' 等，根据需求调整
          formatter: '{b}', // 这里使用内置模板，{b}表示显示数据项的名称，也就是对应你配置里的 'Search Engine' 等名称，如果想同时显示名称和数值可以用 '{b}: {c}'，{c} 代表数值
          textStyle: {
            color: '#000', // 设置文字颜色，这里示例为黑色，可以按需修改
            fontSize: 12 // 设置文字字体大小，示例为12px，可调整
          }
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          {value: sendRecordSpread.collegeCount, name: '专科'},
          {value: sendRecordSpread.bachelorCount, name: '本科'},
          {value: sendRecordSpread.masterCount, name: '硕士'},
          {value: sendRecordSpread.doctorCount, name: '博士'},
          {value: sendRecordSpread.otherCount, name: '其他'}
        ]
      }
    ]
  };
  // 使用配置项显示图表
  myChart2.setOption(option2);
}
//获取当前登录用户信息
import {useUserStore} from "@/stores/user.js";
const userStore = useUserStore();
const userInfo = userStore.userInfo;
const enterpriseUserId=userInfo.userId;
onMounted(() => {
  setChart1(enterpriseUserId)
  setChart2(enterpriseUserId)
});

//公告栏
// 新增方法用于将回车替换微br空格替换微&nbsp
const truncateText1 = (text) => {
  return text.replace(/\n/g, '<br>').replace(/ /g, '&nbsp;');
};
// 新增方法用于截断文本并添加省略号
const truncateText2 = (text) => {
  return text.slice(0, 20) + '. . . . .';
};
const open = ref(false);
const textContent = ref('');
const textTitle = ref('');
const showModal = async (bulletinId) => {
  open.value = true;
  const res = await queryBulletinDetailByIdAPI(bulletinId)
  if (res.data.flag) {
    textContent.value = res.data.data.bulletinText
    textTitle.value = res.data.data.bulletinTitle
  }
};
const handleOk = () => {
  open.value = false;
};
import {
  pageBulletinAPI,
  queryBulletinDetailByIdAPI,
} from "@/apis/bulletin.js";
import {onMounted, reactive, ref} from "vue";
import {querySendRecordChangeAPI, querySendRecordSpreadAPI} from "@/apis/chart.js";
import {queryInformationByUserIdAPI} from "@/apis/enterprise.js";

const listData = ref([]);
const data = ref({pageCurrent: 1, pageSize: 6, searchName: '',});
const getData = async (data) => {
  const res = await pageBulletinAPI(data)
  pagination.total = res.data.data.total
  listData.value = res.data.data.data
}
const pagination = {
  onChange: page => {
    console.log(page);
    data.value.pageCurrent = page
    getData(data.value)
  },
  pageSize: 6,
  total: 0,
};


// 生命周期
onMounted(() => {
  getData(data.value);
});

//搜索
const onSearch = searchValue => {
  console.log('use value', searchValue);
  getData(data.value);
};


</script>
<style lang="scss" scoped>
.admin-home {
  height: auto;
  margin: -20px;
  .div-2{
    display: flex;
    flex-wrap: wrap;
    width: 100%;

    .list-item {
      width: 30%;
      display: inline-block; // 让列表项横排显示，设置为行内块元素
      vertical-align: top; // 让列表项顶部对齐，视觉上更整齐，可选设置
      &:last-child {
        margin-right: 0; // 最后一个列表项去掉右侧间距，可选优化
      }
    }

    // 如果内部的 a-card 等元素宽度超出了父容器宽度，也需要设置其能自动换行
    a-card {
      display: block; // 确保内部卡片元素占满一行宽度等情况，可根据实际调整
      word-break: break-all; // 允许单词内换行，避免内容过长超出不换行情况
      width: 100%;
    }
  }
}


:deep(.slick-slide) {
  text-align: center;
  line-height: 160px;
  background: #364d79;
  overflow: hidden;
}

:deep(.slick-arrow.custom-slick-arrow) {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  transition: ease all 0.3s;
  opacity: 0.3;
  z-index: 1;
}

:deep(.slick-arrow.custom-slick-arrow:before) {
  display: none;
}

:deep(.slick-arrow.custom-slick-arrow:hover) {
  color: #fff;
  opacity: 0.5;
}


</style>